using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SchemaMonitor;
using Framework;
using System.Web.UI.HtmlControls;

public partial class pages_books_usercontrols_UCBook : UserControl 
{     
    #region Members
    private CBook _book; 
    private IList _sortedList; 
    #endregion 
    
    #region Interface
    public void Display(CBook book, IList sortedList) 
    { 
        if (Parent.Controls.Count % 2 == 0) 
            row.Attributes.Add("class", "alt_row"); 
        
        _book = book; 
        _sortedList = sortedList;
         
        CBook c = _book; 
        litNumber.Text = Convert.ToString(sortedList.IndexOf(c) + 1);
        lnkBookName.Text = c.NameAndCount; 
        lnkBookName.NavigateUrl = CSitemap.BookEdit(c.BookId); 
        litBookCreated.Text = CUtilities.Timespan(c.BookCreated);
		litBookCreated.ToolTip = CUtilities.LongDateTime(c.BookCreated);

		foreach (var i in book.Sections)
			ShowSection(i);

		lnkNewSection.NavigateUrl = "~/?sectionId=-2";
	}
	private void ShowSection(CSection s)
	{
		var li = new HtmlGenericControl("li");
		ol.Controls.Add(li);

		var lnk = new HyperLink();
		li.Controls.Add(lnk);
		lnk.NavigateUrl = CSitemap.SectionEdit(s);
		lnk.ToolTip = s.SectionName;
		lnk.Text = CUtilities.Truncate(s.NameAndCount);
		
	}
	#endregion

	#region Event Handlers 
	protected void btnDelete_Click(object sender, ImageClickEventArgs e) 
    {
        _book.Delete(); 
        Refresh(); 
    } 
    #endregion 
    
    #region Private
    private void Refresh() 
    { 
        Response.Redirect(Request.RawUrl); 
    } 
    #endregion 
} 
